﻿@inject IWebHelper webHelper
@inject IDateTimeHelper dateTimeHelper
@inject IPermissionService permissionService
@inject ICustomerService customerService
@inject IEventPublisher eventPublisher
@inject CommonSettings commonSettings
@inject LocalizationSettings localizationSettings
@inject StoreInformationSettings storeInformationSettings
@inject INopFileProvider fileProvider;
@inject Microsoft.AspNetCore.Hosting.IWebHostEnvironment WebHostEnvironment
@inject Nop.Services.Localization.ILanguageService languageService
@using System.Globalization
@using Nop.Core.Domain
@using Nop.Core.Domain.Localization
@using Nop.Services.Common
@using Nop.Services.Customers
@using Nop.Services.Helpers
@using Nop.Services.Security
@using Nop.Web.Framework.UI

@{
    var returnUrl = webHelper.GetRawUrl(Context.Request);

    //Kendo UI
    var kendoVersion = "2020.1.406";

    var currentKendoCulture = (await EngineContext.Current.Resolve<IWorkContext>().GetWorkingLanguageAsync()).LanguageCulture;

    var currentCulture = CultureInfo.CurrentCulture;

    //Code to get check if current cultures scripts are exists. If not, select parent cultures scripts
    string GetDefaultLocale()
    {
        var localePattern = NopCommonDefaults.LocalePatternPath;

        var cultureToUse = NopCommonDefaults.DefaultLocalePattern; //Default regionalisation to use

        if (fileProvider.DirectoryExists(fileProvider.Combine(WebHostEnvironment.WebRootPath, string.Format(localePattern, currentCulture.Name))))
            cultureToUse = currentCulture.Name;
        else if (fileProvider.DirectoryExists(fileProvider.Combine(WebHostEnvironment.WebRootPath, string.Format(localePattern, currentCulture.TwoLetterISOLanguageName))))
            cultureToUse = currentCulture.TwoLetterISOLanguageName;

        return cultureToUse;
    }

    var supportRtl = (await workContext.GetWorkingLanguageAsync()).Rtl && !localizationSettings.IgnoreRtlPropertyForAdminArea;

    //CSS resources
    if (supportRtl)
    {
        Html.AppendCssFileParts("~/css/admin/styles.rtl.css");
        Html.AppendCssFileParts("~/lib/adminLTE/css/adminlte-rtl.min.css");
        Html.AppendCssFileParts("~/lib_npm/@laylazi/bootstrap-rtl/css/bootstrap-rtl.min.css");
    }
    else
    {
        Html.AppendCssFileParts("~/css/admin/styles.css");
        Html.AppendCssFileParts("~/lib_npm/admin-lte/css/adminlte.min.css");
        Html.AppendCssFileParts("~/lib_npm/bootstrap/css/bootstrap.min.css");
    }

    Html.AppendCssFileParts($"~/lib_npm/overlayscrollbars/css/OverlayScrollbars.min.css");
    Html.AppendCssFileParts($"~/lib_npm/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css");
    Html.AppendCssFileParts($"~/lib_npm/datatables.net-bs4/css/dataTables.bootstrap4.min.css");
    Html.AppendCssFileParts($"~/lib/kendo/{kendoVersion}/styles/web/kendo.rtl.min.css");
    Html.AppendCssFileParts($"~/lib/kendo/{kendoVersion}/styles/web/kendo.default.min.css");
    Html.AppendCssFileParts($"~/lib/kendo/{kendoVersion}/styles/web/kendo.common.min.css");
    Html.AppendCssFileParts("~/lib_npm/@fortawesome/fontawesome-free/css/all.min.css");
    Html.AppendCssFileParts("~/lib_npm/bootstrap-touchspin/jquery.bootstrap-touchspin.min.css");
    Html.AppendCssFileParts("~/lib_npm/jquery-ui-dist/jquery-ui.min.css");

    //scripts
    Html.AppendScriptParts($"~/lib_npm/datatables.net-buttons-bs4/js/buttons.bootstrap4.min.js");
    Html.AppendScriptParts($"~/lib_npm/datatables.net-buttons/js/dataTables.buttons.min.js");
    Html.AppendScriptParts($"~/lib_npm/moment/min/moment-with-locales.min.js");
    Html.AppendScriptParts($"~/lib_npm/datatables.net-bs4/js/dataTables.bootstrap4.min.js");
    Html.AppendScriptParts($"~/lib_npm/datatables.net/js/jquery.dataTables.min.js");
    Html.AppendScriptParts($"~/lib/kendo/{kendoVersion}/js/cultures/kendo.culture.{currentKendoCulture}.min.js");
    var fileInfo = fileProvider.GetFileInfo($"{WebHostEnvironment.WebRootPath}/lib/kendo/{kendoVersion}/js/messages/kendo.messages.{currentKendoCulture}.min.js");
    @if (fileInfo.Exists)
    {
        Html.AppendScriptParts($"~/lib/kendo/{kendoVersion}/js/messages/kendo.messages.{currentKendoCulture}.min.js");
    }
    else
    {
        Html.AppendScriptParts($"~/lib/kendo/{kendoVersion}/js/messages/kendo.messages.{NopCommonDefaults.DefaultLanguageCulture}.min.js");
    }
    Html.AppendScriptParts($"~/lib/kendo/{kendoVersion}/js/kendo.ui.core.min.js");

    Html.AppendScriptParts("~/js/admin.search.js");
    Html.AppendScriptParts("~/js/admin.navigation.js");
    Html.AppendScriptParts("~/js/admin.common.js");
    Html.AppendScriptParts("~/lib_npm/typeahead.js/typeahead.bundle.min.js");
    Html.AppendScriptParts("~/lib_npm/jquery-migrate/jquery-migrate.min.js");

    // this file can be downloaded from :
    // https://github.com/johnnyreilly/jquery-validation-globalize
    Html.AppendScriptParts("~/lib/jquery-validation-globalize/jquery.validate.globalize.min.js");

    // globalize scripts
    Html.AppendScriptParts("~/lib_npm/globalize/globalize/currency.js");
    Html.AppendScriptParts("~/lib_npm/globalize/globalize/date.js");
    Html.AppendScriptParts("~/lib_npm/globalize/globalize/number.js");
    Html.AppendScriptParts("~/lib_npm/globalize/globalize.js");

    // cldr scripts (needed for globalize)
    Html.AppendScriptParts("~/lib_npm/cldrjs/cldr/supplemental.js");
    Html.AppendScriptParts("~/lib_npm/cldrjs/cldr/event.js");
    Html.AppendScriptParts("~/lib_npm/cldrjs/cldr.js");

    Html.AppendScriptParts("~/lib_npm/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js");
    Html.AppendScriptParts("~/lib_npm/jquery-validation/jquery.validate.min.js");
    Html.AppendScriptParts("~/lib_npm/bootstrap/js/bootstrap.bundle.min.js");
    Html.AppendScriptParts("~/lib_npm/bootstrap-touchspin/jquery.bootstrap-touchspin.min.js");
    Html.AppendScriptParts("~/lib_npm/overlayscrollbars/js/jquery.overlayScrollbars.min.js");
    Html.AppendScriptParts("~/lib_npm/admin-lte/js/adminlte.min.js");
    Html.AppendScriptParts("~/lib_npm/jquery-ui-dist/jquery-ui.min.js");
    Html.AppendScriptParts("~/lib_npm/jquery/jquery.min.js");

    //page title
    string adminPageTitle = !string.IsNullOrWhiteSpace(ViewBag.PageTitle) ? ViewBag.PageTitle + " / " : "";
    adminPageTitle += T("Admin.PageTitle").Text;

    //has "Manage Maintenance" permission?
    var canManageMaintenance = await permissionService.AuthorizeAsync(StandardPermissionProvider.ManageMaintenance);

    //avatar
    var currentCustomer = await workContext.GetCurrentCustomerAsync();

    //event
    await eventPublisher.PublishAsync(new PageRenderingEvent(this.Html));

    //info: we specify "Admin" area for actions and widgets here for cases when we use this layout in a plugin that is running in a different area than "admin"
}
<!DOCTYPE html>
<html lang="@languageService.GetTwoLetterIsoLanguageName(await workContext.GetWorkingLanguageAsync())" @(supportRtl ? Html.Raw(" dir=\"rtl\"") : null)>
<head>
    <title>@adminPageTitle</title>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    @*Google Font*@
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
    <script>
            var rootAppPath = '@(Url.Content("~/"))';
    </script>
    @Html.NopHeadCustom()
    @Html.NopCssFiles(ResourceLocation.Head, false)
    @Html.NopScripts(ResourceLocation.Head, false)
    @*Insert favicon and app icons head code*@
    @await Component.InvokeAsync("Favicon")
    @Html.NopInlineScripts(ResourceLocation.Head)
</head>
<body class="hold-transition sidebar-mini layout-fixed control-sidebar-slide-open">
    <script type="text/javascript">
            var culture = "@GetDefaultLocale()";

            //load cldr for current culture
            $.when(
                $.get("/lib_npm/cldr-data/supplemental/likelySubtags.json"),
                $.get("/lib_npm/cldr-data/main/" + culture + "/numbers.json"),
                $.get("/lib_npm/cldr-data/main/" + culture + "/currencies.json"),
                $.get("/lib_npm/cldr-data/supplemental/numberingSystems.json"),
                $.get("/lib_npm/cldr-data/main/" + culture + "/ca-gregorian.json"),
                $.get("/lib_npm/cldr-data/main/" + culture + "/timeZoneNames.json"),
                $.get("/lib_npm/cldr-data/supplemental/timeData.json"),
                $.get("/lib_npm/cldr-data/supplemental/weekData.json"),
            ).then(function () {
                // Normalize $.get results, we only need the JSON, not the request statuses.
                return [].slice.apply(arguments, [0]).map(function (result) {
                    return result[0];
                });
            }).then(Globalize.load).then(function () {
                Globalize.locale(culture);
            });
    </script>
    <script>
            kendo.culture("@(currentKendoCulture)");
    </script>
    <div class="throbber">
        <div class="curtain">
        </div>
        <div class="curtain-content">
            <div>
                <h1 class="throbber-header">@T("Common.Wait")</h1>
                <p>
                    <img src="@Url.Content("~/css/admin/images/throbber-synchronizing.gif")" alt="" />
                </p>
            </div>
        </div>
    </div>
    <div id="ajaxBusy">
        <span>&nbsp;</span>
    </div>
    <div class="wrapper">
        @if (IsSectionDefined("header"))
        {
            @RenderSection("header")
        }
        else
        {
            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.HeaderBefore })
            <nav class="main-header navbar navbar-expand-md navbar-dark bg-dark">
                <ul class="navbar-nav pl-2 pl-md-0">
                    <li class="nav-item">
                        <a class="nav-link" id="nopSideBarPusher" data-widget="pushmenu" href="#"><i class="fa fa-bars"></i></a>
                    </li>
                    @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.HeaderToggleAfter })
                </ul>
                <a href="@Url.Content("~/Admin")" class="brand-link navbar-dark">
                    <img src="~/css/admin/images/logo.png" alt="logo.png" class="brand-image logo d-block d-md-none d-sm-block d-sm-none">
                </a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.HeaderNavbarBefore })
                <div class="collapse navbar-collapse" id="navbarText">
                    <ul class="navbar-nav ml-auto pl-2">
                        <li class="nav-item">
                            @await Component.InvokeAsync("AdminLanguageSelector")
                        </li>
                        @if (await customerService.IsRegisteredAsync(currentCustomer))
                        {
                            <li class="nav-item">
                                <a href="#" class="nav-link disabled">@await customerService.GetCustomerFullNameAsync(currentCustomer)</a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="Customer" asp-action="Logout" asp-area="" class="nav-link">@T("Admin.Header.Logout")</a>
                            </li>
                        }
                        <li class="nav-item">
                            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.HeaderMiddle })
                        </li>
                        <li class="nav-item">
                            <a asp-controller="Home" asp-action="Index" asp-area="" class="nav-link">@T("Admin.Header.PublicStore")</a>
                        </li>
                        @if (canManageMaintenance)
                        {
                            <li class="nav-item dropdown">
                                <a class="nav-link" href="#" data-toggle="dropdown">
                                    <i class="fas fa-cogs"></i>
                                </a>
                                <ul class="maintenance-menu dropdown-menu dropdown-menu-right" role="menu">
                                    <li class="dropdown-item">
                                        <form asp-controller="Common" asp-action="ClearCache" asp-area="@AreaNames.Admin">
                                            <input name="returnurl" type="hidden" value="@returnUrl">
                                            <div class="input-group-append">
                                                <button type="submit" style="width:210px;background-color: Transparent;">
                                                    <span>@T("Admin.Header.ClearCache")</span>
                                                </button>
                                            </div>
                                        </form>
                                    </li>
                                    <li class="dropdown-item">
                                        <form asp-controller="Common" asp-action="RestartApplication" asp-area="@AreaNames.Admin">
                                            <input name="returnurl" type="hidden" value="@returnUrl">
                                            <button id="restart-application" type="submit" style="width:210px;background-color: Transparent;">
                                                <span>@T("Admin.Header.RestartApplication")</span>
                                            </button>
                                            <script>
                                $(document).ready(function () {
                                    $("#restart-application").click(function (e) {
                                        showThrobber('@Html.Raw(JavaScriptEncoder.Default.Encode(T("Admin.Header.RestartApplication.Progress").Text))');
                                    });
                                });
                                            </script>
                                        </form>
                                    </li>
                                </ul>
                            </li>
                        }
                    </ul>
                </div>
                @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.HeaderNavbarAfter })
            </nav>

            @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.HeaderAfter })
        }
        @if (IsSectionDefined("headermenu"))
        {
            @RenderSection("headermenu")
        }
        else
        {
            <aside class="main-sidebar sidebar-dark-primary elevation-4">
                <!-- Brand Logo -->
                <a href="@Url.Content("~/Admin")" class="brand-link navbar-dark logo-switch">
                    <img src="~/css/admin/images/logo.png" alt="logo.png" class="brand-image-xl logo-xl">
                    <img src="~/css/admin/images/logo-mini.png" alt="logo.png" class="brand-image-xs logo-xs">
                </a>
                <div class="sidebar">
                    <div class="sidebar-form">
                        <div id="search-box">
                            <input type="text" class="form-control admin-search-box typeahead" placeholder="@T("Admin.Menu.Search")">
                        </div>
                    </div>
                    <nav class="mt-2">
                        @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.SearchBoxBefore })
                        <script>
                            $(document).ready(function () {
                                Admin.Search.init();
                            });
                        </script>
                        @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.MenuBefore })
                        @await Html.PartialAsync("Menu")

                    </nav>
                </div>
            </aside>
        }
        <div class="content-wrapper">
            @await Html.PartialAsync("Notifications")
            <nop-antiforgery-token />
            @RenderBody()
        </div>
        <div class="main-footer">
            <div class="container-fluid">
                <div class="col-md-12">
                        <div class="row">
                            @if (!storeInformationSettings.HidePoweredByNopCommerce)
                            {
                                <div class="col-md-4 col-xs-12 text-md-left text-center">
                                    @*Would you like to remove the "Powered by nopCommerce" link in the bottom of the footer?
                        Please find more info at https://www.nopcommerce.com/nopcommerce-copyright-removal-key*@
                                    Powered by <a href="@(OfficialSite.Main + Utm.OnAdminFooter)" target="_blank">nopCommerce</a>
                                </div>
                            }else
                            {
                                <div class="col-md-4 col-xs-12"></div>
                            }
                            <div class="col-md-4 col-xs-12 text-center">
                                @((await dateTimeHelper.ConvertToUserTimeAsync(DateTime.Now)).ToString("f", currentCulture))
                            </div>
                            <div class="col-md-4 col-xs-12 text-md-right text-center">
                                <b>nopCommerce version @NopVersion.FULL_VERSION</b>
                            </div>
                        </div>
                    </div>
            </div>
        </div>
    </div>
    <script>
        var AdminLTEOptions = {
            boxWidgetOptions: {
                boxWidgetIcons: {
                    collapse: 'fa-minus',
                    open: 'fa-plus'
                }
            }
        };
    </script>
    @{
        //scroll to a selected card (if specified)
        var selectedCardName = Html.GetSelectedCardName();
        if (!String.IsNullOrEmpty(selectedCardName))
        {
            <script>
                    location.hash = '#@(selectedCardName)';
            </script>
        }
    }
    @Html.NopCssFiles(ResourceLocation.Footer)
    @Html.NopScripts(ResourceLocation.Footer)
    <a id="backTop" class="btn btn-back-top bg-teal"></a>
    <script>
        $(document).ready(function () {
            //enable "back top" arrow
            $('#backTop').backTop();

            //enable tooltips
            $('[data-toggle="tooltip"]').tooltip({ placement: 'bottom' });
        });
    </script>
    @Html.NopInlineScripts(ResourceLocation.Footer)
</body>
</html>